#include "AMView.h"
#include "../IO/AudioModule.h"
#include <ncurses.h>
#include "Settings.h"

AMView::AMView(AudioModule & am) : am(am) {}
AMView::AMView() {}

AudioModule & AMView::getAudio(){
	return am;
}

void AMView::playMode(int row, int oldCol, int firstLineShown, int bookSize) { 
	WINDOW * win = createWindow(row/3, oldCol, row/3, 0);
	mvwprintw(win,3,3,("PLAYING  " + am.getCurrentFileName()).c_str());
	wrefresh(win);
	int ch;
	while ((ch = getch()) != PM_CLOSE) {
		switch (ch) {
			case PM_STOP : am.stop(); 
				       //wclear(win);
				       mvwprintw(win,3,3, "STOP                                                     ");
				       break;
			case PM_PLAY : am.play(); 
				       //wclear(win);
				       if (am.isPlaying())
						mvwprintw(win,3,3,("PLAYING  " + am.getCurrentFileName()).c_str());
					else
						mvwprintw(win,3,3,"NOT PLAYING                                                      ");
				       break;
			case PM_FORWARD : am.nextFile(); break;
			case PM_ADJUST : am.adjust((firstLineShown + 0.0)/bookSize);
			mvwprintw(win,3,3,("PLAYING  " + am.getCurrentFileName()).c_str());
			break;
		}
		wrefresh(win);
	}
	destroyWindow(win);
}


WINDOW * AMView::createWindow(int h, int w, int x, int y) {
	WINDOW * win = newwin(h,w,x,y);
	box(win,0,0);
	wrefresh(win);
	return win;
}
void AMView::destroyWindow(WINDOW * win) {
	wborder(win,' ',' ',' ',' ',' ',' ',' ',' ');
	wrefresh(win);
	delwin(win);
}
